
********************************************************************************
****** The Effects of WWII on Economic and Health Outcomes across Europe *******
********************************************************************************
* Authors: Iris Kesternich, Bettina Siflinger, James P. Smith, Joachim Winter
* Review of Economics and Statistics, 2014
********************************************************************************
* DOFILE: PSEUDO PANEL SETUP
********************************************************************************


clear
clear matrix
clear mata
set more off


*** define the path to the directory containing the data files here 
*** or leave "." if the do files are in the current directory 

global datapath "."

*** define the path to the directory to which figures are saved here 
*** or leave "." if they should be saved to the current directory 

global graphpath  "."


use "$datapath\final\WWII_final.dta", clear


gen yrbirth3_10 = yrbirth3+10


ren gdp gdp_10
ren comb_sum comb_sum_main




********************************************************************************
*** GENERATE PSEUDO PANEL
********************************************************************************


*** HUNGER PERIODS 

* we want paneldata along the dimension hunger
* generate variables for hunger start and hunger end for each year from 1920 till 1990
forvalues i= 1920(1)1990 {
gen hunger_start`i' = .
}
forvalues i= 1920(1)1990 {
replace hunger_start`i' = 1 if start_hung == `i' & start_hung ~= .
}

forvalues i= 1920(1)1990 {
gen hunger_end`i' = .
}
forvalues i= 1920(1)1990 {
replace hunger_end`i' = 1 if end_hung == `i' & end_hung~= .
}





*** DISPOSSESSION 

forvalues i= 1920(1)1990 {
gen dispos_timing`i' = .
}

forvalues i = 1920(1)1990 {
	replace dispos_timing`i' = 1 if sl_gl033_1 == `i' & sl_gl033_1 ~= .
	replace dispos_timing`i' = 1 if sl_gl033_2 == `i' & sl_gl033_2 ~= . & sl_gl033_1 ~= .
	replace dispos_timing`i' = 1 if sl_gl033_3 == `i' & sl_gl033_3 ~= . & sl_gl033_1 ~= . & sl_gl033_2 ~= .
}





*** RESIDENCE INFORMATION 

* 1. start living at a new residence
set more off
forvalues i = 1907(1)1990 {
	gen start_new_residence_`i' = 0
	forvalues j = 1/29 {
	replace start_new_residence_`i' = 1 if sl_ac006_`j' == `i' & sl_ac006_`j' ~= .
	}
}

* 2. stopped living at a residence
set more off
forvalues i = 1907(1)1990 {
	gen stop_new_residence_`i' = 0
	forvalues j = 1/28 {
	replace stop_new_residence_`i' = 1 if sl_ac021_`j' == `i' & sl_ac021_`j' ~= .
	}
}

* 3. Urban/rural residence
set more off
forvalues i = 1907(1)1990 {
	gen area_residence_`i' = 0
	forvalues j = 1/29 {
	replace area_residence_`i' = 1 if sl_ac017_`j' == 1 & sl_ac006_`j' == `i' & sl_ac017_`j' ~= .
	replace area_residence_`i' = 2 if sl_ac017_`j' == 2 & sl_ac006_`j' == `i' & sl_ac017_`j' ~= .
	replace area_residence_`i' = 3 if sl_ac017_`j' == 3 & sl_ac006_`j' == `i' & sl_ac017_`j' ~= .
	replace area_residence_`i' = 4 if sl_ac017_`j' == 4 & sl_ac006_`j' == `i' & sl_ac017_`j' ~= .
	replace area_residence_`i' = 5 if sl_ac017_`j' == 5 & sl_ac006_`j' == `i' & sl_ac017_`j' ~= .
	}
}

* region of residence
set more off
forvalues i = 1907(1)1990 {
	gen region_residence_`i' = 0
	forvalues j = 1/29 {
	replace region_residence_`i' = sl_ac015c_`j' if sl_ac006_`j' == `i' & sl_ac015c_`j' ~= .
	}
}


drop comb_sum_main

* keep only variables of interest for figure
keep mergeid country gender mobirth3 yrbirth3 ever_marr hunger start_hung end_hung persec dispos ses ses_low ses_med ses_high war nativeborn comb_yrs comb1_3 ///
comb_sum* hunger_start* hunger_end* dispos_timing* area_residence_* region_residence_* stop_new_residence_* start_new_residence_*





********************************************************************************
*** reshape data in order to obtain long format pseudo panel
********************************************************************************

compress
set more off


reshape long comb_sum@ hunger_start@ hunger_end@ start_new_residence_@ stop_new_residence_@ ///
area_residence_@ region_residence_@ dispos_timing@, i(mergeid) j(year)





********************************************************************************
*** checks
********************************************************************************

replace hunger_start = 0 if hunger_start == .
replace hunger_end = 0 if hunger_end == .

gen hunger_period = 0
replace hunger_period = 1 if hunger_start == 1 
replace hunger_period = 1 if hunger_end == 1

encode mergeid, gen(mergeid2)
sort mergeid2 year
by mergeid2 (year): gen n = _n

set more off
gen hunger_start2 = hunger_start
gen hunger_end2 = hunger_end
forvalues i=1/101 {
by mergeid2 (year): replace hunger_start2 = 1 if hunger_start2[n-`i'] == 1
by mergeid2 (year): replace hunger_end2   = 1 if hunger_end2[n-`i'] == 1
}

forvalues i = 0/101 {
by mergeid2 (year): replace hunger_period = 1 if hunger_start2 == 1 & hunger_end2 == 0
}
drop hunger_start2 hunger_end2



*** check timing of dispossession
replace dispos_timing = 0 if dispos_timing == . & dispos ~= .



*** check regions at different time periods
sort mergeid2 year
gen region_test = region_residence
replace region_test = . if region_test == 0 & year < yrbirth3

forvalues i= 0/101 {
by mergeid2 (year): replace region_test = region_residence[n - `i'] if region_test[n] == 0 ///
& region_residence[n-`i'] ~= 0 
}

forvalues i= 0/101 {
by mergeid2 (year): replace region_test = region_residence[n + `i'] if region_test[n] == . & yrbirth3 < year
}
replace region_residence = region_test
drop region_test




*** check area of residence at different time periods
gen area_test = area_residence
replace area_test = . if area_residence == 0 & year < yrbirth3

forvalues i= 1/101 {
by mergeid2 (year): replace area_test = area_residence[n - `i'] if area_test[n] == 0 ///
& area_residence[n-`i'] ~= 0 
}
replace area_residence = area_test
drop area_test



*** only keep observations that are alive at certain dates (result: unbalanced panel)
sort mergeid year
by mergeid (year): drop if year < yrbirth3


save "$datapath\final\share_panel.dta", replace




